﻿using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;

namespace PmfWeb.Core.Web
{
    public class SubService
    {

        ///<summary>
        /// 创建指定类型的实例
        ///</summary>
        ///<typeparam name="T">类型</typeparam>
        ///<returns>类型对象</returns>
        public T GetService<T>()
        {
            return Activator.CreateInstance<T>();
        }
        ///<summary>
        /// 反射创建对象，并缓存对象
        ///</summary>
        ///<typeparam name="T"></typeparam>
        ///<returns></returns>
        public T GetServiceByCache<T>()
        {
            string key = typeof (T).ToString().Replace(".", "_");
            object cacheObj = DataCache.GetCache(key);
            if (null != cacheObj) return (T) cacheObj;

            T obj = Activator.CreateInstance<T>();
            
            DataCache.SetCache(typeof (T).ToString(), obj, null, 60, CacheTimeFormat.Day);
            return obj;
        }
    }
}
